﻿using System;
using System.Web.UI;


namespace mojoPortal.Web.RS.SBM
{
    public partial class RSLocationHistoryCalls : RSBasePage
    {
        int _companyid = 0;
        int _locationid = 0;

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(Request.QueryString["locationid"]))
                _locationid = Convert.ToInt32(Request.QueryString["locationid"].ToString());

            if (!Page.IsPostBack)
            {
                InitializeReadyServicePage("Location History");
                if (_locationid > 0)
                {
                    RSUserIdentity userIdentity = GetRSUserIdentity();
                    _companyid = userIdentity.RSCompanyId;
                    ucLocationHeaderControl.LoadLocationHeader(_companyid, _locationid);
                    ucCallListControl.LoadCallDataByLocationID(_companyid, _locationid);
                }
            }


        }
        protected void lnkMapIt_Click(object sender, EventArgs e)
        {
            RSUserIdentity userIdentity = GetRSUserIdentity();
            int companyid = userIdentity.RSCompanyId; ;
            int locationid = ucLocationHeaderControl.LocationId;
            if (companyid > 0 && locationid > 0)
                ucModalViewMapControl.ShowMapDataByLocationID(companyid, locationid);
        }

        private void ActiveTabChanged(int locationid)
        {
            if (locationid > 0)
            {
                switch (tcLocationHistory.ActiveTabIndex)
                {
                    case 0:
                        //Response.Redirect("RSLocationHistoryCalls.aspx?locationid=" + locationid);
                        break;
                    case 1:
                        Response.Redirect("RSLocationHistoryContacts.aspx?locationid=" + locationid);
                        break;
                    case 2:
                        Response.Redirect("RSLocationHistoryVisits.aspx?locationid=" + locationid);
                        break;
                    case 3:
                        Response.Redirect("RSLocationHistoryEstimates.aspx?locationid=" + locationid);
                        break;
                    case 4:
                        Response.Redirect("RSLocationHistoryWorkOrders.aspx?locationid=" + locationid);
                        break;
                    case 5:
                        Response.Redirect("RSLocationHistoryInvoices.aspx?locationid=" + locationid);
                        break;

                    //default:
                }
            }

        }

        protected void tcLocationHistory_OnActiveTabChanged(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(Request.QueryString["locationid"]))
                _locationid = Convert.ToInt32(Request.QueryString["locationid"].ToString());

            ActiveTabChanged(_locationid);
        }
    }
}


